package com.mmlc.meimei.lichengkongjian.brand;

import android.content.Intent;
import android.view.View;

import com.androidnetframe.BaseParentActivity;
import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.androidnetframe.utils.LogUtils;
import com.mmlc.inter.InterFragment;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.home.SearchActivity;
import com.mmlc.network.filter.BrandListRequestFilter;
import com.mmlc.network.responsebean.BrandListResponseBean;
import com.mmlc.utils.ViewUtils;
import com.mmlc.widget.BladeListView;

import java.util.List;

public class BrandFragment extends InterFragment {

    @Override
    protected int initResourceID() {
        return R.layout.fragment_brand;
    }

    BladeListView blade_listview;

    @Override
    protected void initView() {
        blade_listview = ViewUtils.getView(view, R.id.blade_listview);

        blade_listview.setChildClickedListener(new BladeListView.ChildClickedListener() {
            @Override
            public void childClicked(String brandId, String brandName) {
                Intent intent = new Intent(getActivity(), BrandInfoActivity.class);
                intent.putExtra("name", brandName);
                intent.putExtra("brand_id", brandId);

                startActivity(intent);
            }
        });
    }

    List<BrandListResponseBean.DataBean> datas;

    @Override
    protected void initInfo() {
        super.initInfo();

        BrandListRequestFilter filter = new BrandListRequestFilter((BaseParentActivity) getActivity());
        filter.requestBean.method = "brandList";
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<BrandListResponseBean>() {
            @Override
            public void onSuccess(BrandListResponseBean result) {
                if (result == null) {
                    result = new BrandListResponseBean();
                }

                LogUtils.i(TAG, "brandList:" + result.toString());
                if (result.getData() != null) {
                    datas = result.getData();
                    blade_listview.setDatas(datas);
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {

            }
        });
    }

    @Override
    protected void initEvent() {
        super.initEvent();

        ViewUtils.getView(view, R.id.iv_search).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_search:
                startActivity(new Intent(getActivity(), SearchActivity.class));
                break;
        }
    }
}
